package com.example.app;

import android.app.Dialog;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.getcapacitor.JSObject;
import com.getcapacitor.Logger;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;

import java.io.File;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import cn.wps.moffice.demo.client.MOfficeClientService;
import cn.wps.moffice.demo.fileManager.OpenFile;
import cn.wps.moffice.demo.util.Define;
import cn.wps.moffice.demo.util.SettingPreference;
import cn.wps.moffice.demo.util.Util;
import cn.wps.moffice.service.OfficeService;

@NativePlugin()
public class WpsPlugin extends Plugin {

    @PluginMethod()
    public void editAndSave(PluginCall call) {
        Intent intent = new Intent(getContext(),WpsFileActivity.class);
        Bundle bundle = new Bundle();
        if(null == call.getString("downloadUrl")){
            call.reject("downloadUrl参数不存在！");
        }
        if(null == call.getString("uploadUrl")){
            call.reject("uploadUrl参数不存在！");
        }
        if(null == call.getString("filename")){
            call.reject("filename参数不存在！");
        }
        bundle.putString("downloadUrl", call.getString("downloadUrl"));
        bundle.putString("uploadUrl", call.getString("uploadUrl"));
        bundle.putString("filename", call.getString("filename"));
        intent.putExtras(bundle);

        ((MainActivity)getContext()).wpsPluginCallback = new PluginCallback() {
            @Override
            public void onCallback(int resultCode, Map<String, Object> resultMap) {
                JSObject ret = new JSObject();
                if(resultCode == 1){
                    ret.put("success", true);
                }else{
                    ret.put("success", false);
                }
                call.resolve(ret);
            }
        };
        getContext().startActivity(intent);
    }

    @PluginMethod()
    public void echo(PluginCall call) {
        String value = call.getString("value");
        JSObject ret = new JSObject();
        ret.put("value", value);
        call.resolve(ret);
    }
}


